{
 "cells": [
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-22T03:55:54.841374Z",
     "start_time": "2025-01-22T03:55:53.717417Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import time\n",
    "\n",
    "from sklearn.datasets import load_iris, fetch_20newsgroups, fetch_california_housing\n",
    "from sklearn.model_selection import train_test_split, GridSearchCV\n",
    "from sklearn.neighbors import KNeighborsClassifier\n",
    "from sklearn.preprocessing import StandardScaler\n",
    "from sklearn.feature_extraction.text import TfidfVectorizer\n",
    "from sklearn.naive_bayes import MultinomialNB\n",
    "from sklearn.metrics import classification_report\n",
    "from sklearn.feature_extraction import DictVectorizer\n",
    "from sklearn.tree import DecisionTreeClassifier, export_graphviz\n",
    "from sklearn.ensemble import RandomForestClassifier\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "from sklearn.metrics import roc_auc_score"
   ],
   "outputs": [],
   "execution_count": 1
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "获取特征值\n",
      "[   8.3252       41.            6.98412698    1.02380952  322.\n",
      "    2.55555556   37.88       -122.23      ]\n",
      "样本的形状\n",
      "(20640, 8)\n",
      "--------------------------------------------------\n"
     ]
    }
   ],
   "execution_count": 11,
   "source": [
    "house=fetch_california_housing(data_home='data')\n",
    "print(\"获取特征值\")\n",
    "print(house.data[0])  #第一个样本特征值\n",
    "print('样本的形状')\n",
    "print(house.data.shape)\n",
    "print('-' * 50)"
   ]
  },
  {
   "cell_type": "code",
   "source": [
    "print(\"目标值\")\n",
    "print(house.target[0:10])\n",
    "print('-' * 50)\n",
    "print(house.DESCR)\n",
    "print('-' * 50)\n",
    "print(house.feature_names)\n",
    "print('-' * 50)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-01-22T02:26:27.314130Z",
     "start_time": "2025-01-22T02:26:27.309926Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "目标值\n",
      "[4.526 3.585 3.521 3.413 3.422 2.697 2.992 2.414 2.267 2.611]\n",
      "--------------------------------------------------\n",
      ".. _california_housing_dataset:\n",
      "\n",
      "California Housing dataset\n",
      "--------------------------\n",
      "\n",
      "**Data Set Characteristics:**\n",
      "\n",
      ":Number of Instances: 20640\n",
      "\n",
      ":Number of Attributes: 8 numeric, predictive attributes and the target\n",
      "\n",
      ":Attribute Information:\n",
      "    - MedInc        median income in block group\n",
      "    - HouseAge      median house age in block group\n",
      "    - AveRooms      average number of rooms per household\n",
      "    - AveBedrms     average number of bedrooms per household\n",
      "    - Population    block group population\n",
      "    - AveOccup      average number of household members\n",
      "    - Latitude      block group latitude\n",
      "    - Longitude     block group longitude\n",
      "\n",
      ":Missing Attribute Values: None\n",
      "\n",
      "This dataset was obtained from the StatLib repository.\n",
      "https://www.dcc.fc.up.pt/~ltorgo/Regression/cal_housing.html\n",
      "\n",
      "The target variable is the median house value for California districts,\n",
      "expressed in hundreds of thousands of dollars ($100,000).\n",
      "\n",
      "This dataset was derived from the 1990 U.S. census, using one row per census\n",
      "block group. A block group is the smallest geographical unit for which the U.S.\n",
      "Census Bureau publishes sample data (a block group typically has a population\n",
      "of 600 to 3,000 people).\n",
      "\n",
      "A household is a group of people residing within a home. Since the average\n",
      "number of rooms and bedrooms in this dataset are provided per household, these\n",
      "columns may take surprisingly large values for block groups with few households\n",
      "and many empty houses, such as vacation resorts.\n",
      "\n",
      "It can be downloaded/loaded using the\n",
      ":func:`sklearn.datasets.fetch_california_housing` function.\n",
      "\n",
      ".. rubric:: References\n",
      "\n",
      "- Pace, R. Kelley and Ronald Barry, Sparse Spatial Autoregressions,\n",
      "  Statistics and Probability Letters, 33 (1997) 291-297\n",
      "\n",
      "--------------------------------------------------\n",
      "['MedInc', 'HouseAge', 'AveRooms', 'AveBedrms', 'Population', 'AveOccup', 'Latitude', 'Longitude']\n",
      "--------------------------------------------------\n"
     ]
    }
   ],
   "execution_count": 12
  },
  {
   "cell_type": "markdown",
   "source": [
    "# 2 分类估计器"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%% md\n"
    }
   }
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": [
    "# k-近邻算法\n",
    "- 定义: 如果一个样本在特征空间中的k个最相似(即特征空间中最邻近)的样本中的大多数属于某一个类别，则该样本也属于这个类别。\n",
    "- 距离公式: 欧式距离 (二维就是勾股定理)"
   ]
  },
  {
   "cell_type": "code",
   "source": [
    "np.sqrt(15*15+14*14)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2025-01-22T02:26:27.321049Z",
     "start_time": "2025-01-22T02:26:27.315122Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "np.float64(20.518284528683193)"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 13
  },
  {
   "cell_type": "code",
   "source": [
    "# K近邻\n",
    "\"\"\"\n",
    "K-近邻预测用户签到位置\n",
    ":return:None\n",
    "\"\"\"\n",
    "# 读取数据\n",
    "data = pd.read_csv(\"./data/FBlocation/train.csv\")\n",
    "\n",
    "print(data.head(10))\n",
    "print(data.shape)\n",
    "print(data.info())"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2025-01-22T02:26:37.540988Z",
     "start_time": "2025-01-22T02:26:27.322047Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   row_id       x       y  accuracy    time    place_id\n",
      "0       0  0.7941  9.0809        54  470702  8523065625\n",
      "1       1  5.9567  4.7968        13  186555  1757726713\n",
      "2       2  8.3078  7.0407        74  322648  1137537235\n",
      "3       3  7.3665  2.5165        65  704587  6567393236\n",
      "4       4  4.0961  1.1307        31  472130  7440663949\n",
      "5       5  3.8099  1.9586        75  178065  6289802927\n",
      "6       6  6.3336  4.3720        13  666829  9931249544\n",
      "7       7  5.7409  6.7697        85  369002  5662813655\n",
      "8       8  4.3114  6.9410         3  166384  8471780938\n",
      "9       9  6.3414  0.0758        65  400060  1253803156\n",
      "(29118021, 6)\n",
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 29118021 entries, 0 to 29118020\n",
      "Data columns (total 6 columns):\n",
      " #   Column    Dtype  \n",
      "---  ------    -----  \n",
      " 0   row_id    int64  \n",
      " 1   x         float64\n",
      " 2   y         float64\n",
      " 3   accuracy  int64  \n",
      " 4   time      int64  \n",
      " 5   place_id  int64  \n",
      "dtypes: float64(2), int64(4)\n",
      "memory usage: 1.3 GB\n",
      "None\n"
     ]
    }
   ],
   "execution_count": 14
  },
  {
   "cell_type": "code",
   "source": [
    "# 处理数据\n",
    "# 1、缩小数据,查询数据,为了减少计算时间\n",
    "data = data.query(\"x > 1.0 &  x < 1.25 & y > 2.5 & y < 2.75\")\n",
    "data.shape"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-01-22T02:26:37.960721Z",
     "start_time": "2025-01-22T02:26:37.541986Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(17710, 6)"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 15
  },
  {
   "cell_type": "code",
   "source": [
    "data.describe()"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-01-22T02:26:37.979534Z",
     "start_time": "2025-01-22T02:26:37.960721Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "             row_id             x             y      accuracy           time  \\\n",
       "count  1.771000e+04  17710.000000  17710.000000  17710.000000   17710.000000   \n",
       "mean   1.450569e+07      1.122538      2.632309     82.482101  397551.263128   \n",
       "std    8.353805e+06      0.077086      0.070144    113.613227  234601.097883   \n",
       "min    6.000000e+02      1.000100      2.500100      1.000000     119.000000   \n",
       "25%    7.327816e+06      1.049200      2.573800     25.000000  174069.750000   \n",
       "50%    1.443071e+07      1.123300      2.642300     62.000000  403387.500000   \n",
       "75%    2.163463e+07      1.190500      2.687800     75.000000  602111.750000   \n",
       "max    2.911215e+07      1.249900      2.749900   1004.000000  786218.000000   \n",
       "\n",
       "           place_id  \n",
       "count  1.771000e+04  \n",
       "mean   5.129895e+09  \n",
       "std    2.357399e+09  \n",
       "min    1.012024e+09  \n",
       "25%    3.312464e+09  \n",
       "50%    5.261906e+09  \n",
       "75%    6.766325e+09  \n",
       "max    9.980711e+09  "
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>row_id</th>\n",
       "      <th>x</th>\n",
       "      <th>y</th>\n",
       "      <th>accuracy</th>\n",
       "      <th>time</th>\n",
       "      <th>place_id</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>1.771000e+04</td>\n",
       "      <td>17710.000000</td>\n",
       "      <td>17710.000000</td>\n",
       "      <td>17710.000000</td>\n",
       "      <td>17710.000000</td>\n",
       "      <td>1.771000e+04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>1.450569e+07</td>\n",
       "      <td>1.122538</td>\n",
       "      <td>2.632309</td>\n",
       "      <td>82.482101</td>\n",
       "      <td>397551.263128</td>\n",
       "      <td>5.129895e+09</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>8.353805e+06</td>\n",
       "      <td>0.077086</td>\n",
       "      <td>0.070144</td>\n",
       "      <td>113.613227</td>\n",
       "      <td>234601.097883</td>\n",
       "      <td>2.357399e+09</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>6.000000e+02</td>\n",
       "      <td>1.000100</td>\n",
       "      <td>2.500100</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>119.000000</td>\n",
       "      <td>1.012024e+09</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>7.327816e+06</td>\n",
       "      <td>1.049200</td>\n",
       "      <td>2.573800</td>\n",
       "      <td>25.000000</td>\n",
       "      <td>174069.750000</td>\n",
       "      <td>3.312464e+09</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>1.443071e+07</td>\n",
       "      <td>1.123300</td>\n",
       "      <td>2.642300</td>\n",
       "      <td>62.000000</td>\n",
       "      <td>403387.500000</td>\n",
       "      <td>5.261906e+09</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>2.163463e+07</td>\n",
       "      <td>1.190500</td>\n",
       "      <td>2.687800</td>\n",
       "      <td>75.000000</td>\n",
       "      <td>602111.750000</td>\n",
       "      <td>6.766325e+09</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>2.911215e+07</td>\n",
       "      <td>1.249900</td>\n",
       "      <td>2.749900</td>\n",
       "      <td>1004.000000</td>\n",
       "      <td>786218.000000</td>\n",
       "      <td>9.980711e+09</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 16
  },
  {
   "cell_type": "code",
   "source": [
    "# 处理时间的数据：unit是秒，把秒转换成日期格式\n",
    "time_value = pd.to_datetime(data['time'], unit='s')\n",
    "\n",
    "print(time_value.head(10))  #最大时间是1月10号"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-01-22T02:26:37.985510Z",
     "start_time": "2025-01-22T02:26:37.980524Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "600    1970-01-01 18:09:40\n",
      "957    1970-01-10 02:11:10\n",
      "4345   1970-01-05 15:08:02\n",
      "4735   1970-01-06 23:03:03\n",
      "5580   1970-01-09 11:26:50\n",
      "6090   1970-01-02 16:25:07\n",
      "6234   1970-01-04 15:52:57\n",
      "6350   1970-01-01 10:13:36\n",
      "7468   1970-01-09 15:26:06\n",
      "8478   1970-01-08 23:52:02\n",
      "Name: time, dtype: datetime64[ns]\n"
     ]
    }
   ],
   "execution_count": 17
  },
  {
   "cell_type": "code",
   "source": [
    "# 把日期格式转换成字典格式，把年，月，日，时，分，秒转换为字典格式，\n",
    "time_value = pd.DatetimeIndex(time_value)\n",
    "print('-' * 50)\n",
    "print(time_value[0:10])"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2025-01-22T02:26:37.991069Z",
     "start_time": "2025-01-22T02:26:37.986507Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "--------------------------------------------------\n",
      "DatetimeIndex(['1970-01-01 18:09:40', '1970-01-10 02:11:10',\n",
      "               '1970-01-05 15:08:02', '1970-01-06 23:03:03',\n",
      "               '1970-01-09 11:26:50', '1970-01-02 16:25:07',\n",
      "               '1970-01-04 15:52:57', '1970-01-01 10:13:36',\n",
      "               '1970-01-09 15:26:06', '1970-01-08 23:52:02'],\n",
      "              dtype='datetime64[ns]', name='time', freq=None)\n"
     ]
    }
   ],
   "execution_count": 18
  },
  {
   "cell_type": "code",
   "source": [
    "data.shape"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2025-01-22T02:26:37.996707Z",
     "start_time": "2025-01-22T02:26:37.991069Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(17710, 6)"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 19
  },
  {
   "cell_type": "code",
   "source": [
    "# 构造一些特征，执行的警告是因为我们的操作是复制，loc是直接放入\n",
    "print(type(data))\n",
    "# data['day'] = time_value.day\n",
    "# data['hour'] = time_value.hour\n",
    "# data['weekday'] = time_value.weekday\n",
    "#日期，是否是周末，小时对于个人行为的影响是较大的(例如吃饭时间去饭店，看电影时间去电影院等),所以才做下面的处理：把日加到最后一列（data.shape[1]=6）\n",
    "data.insert(data.shape[1], 'day', time_value.day) #data.shape[1]是代表插入到最后的意思,一个月的哪一天\n",
    "data.insert(data.shape[1], 'hour', time_value.hour)#是否去一个地方打卡，早上，中午，晚上是有影响的\n",
    "data.insert(data.shape[1], 'weekday', time_value.weekday) #0代表周一，6代表周日，星期几\n",
    "\n",
    "# 把时间戳特征删除\n",
    "data = data.drop(['time'], axis=1)\n",
    "print('-' * 50)\n",
    "data.head()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2025-01-22T02:26:38.008582Z",
     "start_time": "2025-01-22T02:26:37.997704Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "--------------------------------------------------\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "      row_id       x       y  accuracy    place_id  day  hour  weekday\n",
       "600      600  1.2214  2.7023        17  6683426742    1    18        3\n",
       "957      957  1.1832  2.6891        58  6683426742   10     2        5\n",
       "4345    4345  1.1935  2.6550        11  6889790653    5    15        0\n",
       "4735    4735  1.1452  2.6074        49  6822359752    6    23        1\n",
       "5580    5580  1.0089  2.7287        19  1527921905    9    11        4"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>row_id</th>\n",
       "      <th>x</th>\n",
       "      <th>y</th>\n",
       "      <th>accuracy</th>\n",
       "      <th>place_id</th>\n",
       "      <th>day</th>\n",
       "      <th>hour</th>\n",
       "      <th>weekday</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>600</th>\n",
       "      <td>600</td>\n",
       "      <td>1.2214</td>\n",
       "      <td>2.7023</td>\n",
       "      <td>17</td>\n",
       "      <td>6683426742</td>\n",
       "      <td>1</td>\n",
       "      <td>18</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>957</th>\n",
       "      <td>957</td>\n",
       "      <td>1.1832</td>\n",
       "      <td>2.6891</td>\n",
       "      <td>58</td>\n",
       "      <td>6683426742</td>\n",
       "      <td>10</td>\n",
       "      <td>2</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4345</th>\n",
       "      <td>4345</td>\n",
       "      <td>1.1935</td>\n",
       "      <td>2.6550</td>\n",
       "      <td>11</td>\n",
       "      <td>6889790653</td>\n",
       "      <td>5</td>\n",
       "      <td>15</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4735</th>\n",
       "      <td>4735</td>\n",
       "      <td>1.1452</td>\n",
       "      <td>2.6074</td>\n",
       "      <td>49</td>\n",
       "      <td>6822359752</td>\n",
       "      <td>6</td>\n",
       "      <td>23</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5580</th>\n",
       "      <td>5580</td>\n",
       "      <td>1.0089</td>\n",
       "      <td>2.7287</td>\n",
       "      <td>19</td>\n",
       "      <td>1527921905</td>\n",
       "      <td>9</td>\n",
       "      <td>11</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 20
  },
  {
   "cell_type": "code",
   "source": [
    "#星期天，实际weekday的值是6,星期四是3，星期一是0\n",
    "per = pd.Period('2025-01-20 18:00', 'h')\n",
    "per.weekday"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2025-01-22T02:26:38.013153Z",
     "start_time": "2025-01-22T02:26:38.008582Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 21
  },
  {
   "cell_type": "code",
   "source": [
    "#观察数据，看下是否有空值，异常值\n",
    "data.describe()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2025-01-22T02:26:38.034152Z",
     "start_time": "2025-01-22T02:26:38.014152Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "             row_id             x             y      accuracy      place_id  \\\n",
       "count  1.771000e+04  17710.000000  17710.000000  17710.000000  1.771000e+04   \n",
       "mean   1.450569e+07      1.122538      2.632309     82.482101  5.129895e+09   \n",
       "std    8.353805e+06      0.077086      0.070144    113.613227  2.357399e+09   \n",
       "min    6.000000e+02      1.000100      2.500100      1.000000  1.012024e+09   \n",
       "25%    7.327816e+06      1.049200      2.573800     25.000000  3.312464e+09   \n",
       "50%    1.443071e+07      1.123300      2.642300     62.000000  5.261906e+09   \n",
       "75%    2.163463e+07      1.190500      2.687800     75.000000  6.766325e+09   \n",
       "max    2.911215e+07      1.249900      2.749900   1004.000000  9.980711e+09   \n",
       "\n",
       "                day          hour       weekday  \n",
       "count  17710.000000  17710.000000  17710.000000  \n",
       "mean       5.101863     11.485545      3.092377  \n",
       "std        2.709287      6.932195      1.680218  \n",
       "min        1.000000      0.000000      0.000000  \n",
       "25%        3.000000      6.000000      2.000000  \n",
       "50%        5.000000     12.000000      3.000000  \n",
       "75%        7.000000     17.000000      4.000000  \n",
       "max       10.000000     23.000000      6.000000  "
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>row_id</th>\n",
       "      <th>x</th>\n",
       "      <th>y</th>\n",
       "      <th>accuracy</th>\n",
       "      <th>place_id</th>\n",
       "      <th>day</th>\n",
       "      <th>hour</th>\n",
       "      <th>weekday</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>1.771000e+04</td>\n",
       "      <td>17710.000000</td>\n",
       "      <td>17710.000000</td>\n",
       "      <td>17710.000000</td>\n",
       "      <td>1.771000e+04</td>\n",
       "      <td>17710.000000</td>\n",
       "      <td>17710.000000</td>\n",
       "      <td>17710.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>1.450569e+07</td>\n",
       "      <td>1.122538</td>\n",
       "      <td>2.632309</td>\n",
       "      <td>82.482101</td>\n",
       "      <td>5.129895e+09</td>\n",
       "      <td>5.101863</td>\n",
       "      <td>11.485545</td>\n",
       "      <td>3.092377</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>8.353805e+06</td>\n",
       "      <td>0.077086</td>\n",
       "      <td>0.070144</td>\n",
       "      <td>113.613227</td>\n",
       "      <td>2.357399e+09</td>\n",
       "      <td>2.709287</td>\n",
       "      <td>6.932195</td>\n",
       "      <td>1.680218</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>6.000000e+02</td>\n",
       "      <td>1.000100</td>\n",
       "      <td>2.500100</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.012024e+09</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>7.327816e+06</td>\n",
       "      <td>1.049200</td>\n",
       "      <td>2.573800</td>\n",
       "      <td>25.000000</td>\n",
       "      <td>3.312464e+09</td>\n",
       "      <td>3.000000</td>\n",
       "      <td>6.000000</td>\n",
       "      <td>2.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>1.443071e+07</td>\n",
       "      <td>1.123300</td>\n",
       "      <td>2.642300</td>\n",
       "      <td>62.000000</td>\n",
       "      <td>5.261906e+09</td>\n",
       "      <td>5.000000</td>\n",
       "      <td>12.000000</td>\n",
       "      <td>3.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>2.163463e+07</td>\n",
       "      <td>1.190500</td>\n",
       "      <td>2.687800</td>\n",
       "      <td>75.000000</td>\n",
       "      <td>6.766325e+09</td>\n",
       "      <td>7.000000</td>\n",
       "      <td>17.000000</td>\n",
       "      <td>4.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>2.911215e+07</td>\n",
       "      <td>1.249900</td>\n",
       "      <td>2.749900</td>\n",
       "      <td>1004.000000</td>\n",
       "      <td>9.980711e+09</td>\n",
       "      <td>10.000000</td>\n",
       "      <td>23.000000</td>\n",
       "      <td>6.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 22
  },
  {
   "cell_type": "code",
   "source": [
    "# 把签到数量少于n个目标位置删除，place_id是标签，即目标值\n",
    "place_count = data.groupby('place_id').count()\n",
    "place_count"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2025-01-22T02:26:38.044877Z",
     "start_time": "2025-01-22T02:26:38.035536Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "            row_id     x     y  accuracy   day  hour  weekday\n",
       "place_id                                                     \n",
       "1012023972       1     1     1         1     1     1        1\n",
       "1057182134       1     1     1         1     1     1        1\n",
       "1059958036       3     3     3         3     3     3        3\n",
       "1085266789       1     1     1         1     1     1        1\n",
       "1097200869    1044  1044  1044      1044  1044  1044     1044\n",
       "...            ...   ...   ...       ...   ...   ...      ...\n",
       "9904182060       1     1     1         1     1     1        1\n",
       "9915093501       1     1     1         1     1     1        1\n",
       "9946198589       1     1     1         1     1     1        1\n",
       "9950190890       1     1     1         1     1     1        1\n",
       "9980711012       5     5     5         5     5     5        5\n",
       "\n",
       "[805 rows x 7 columns]"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>row_id</th>\n",
       "      <th>x</th>\n",
       "      <th>y</th>\n",
       "      <th>accuracy</th>\n",
       "      <th>day</th>\n",
       "      <th>hour</th>\n",
       "      <th>weekday</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>place_id</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1012023972</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1057182134</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1059958036</th>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1085266789</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1097200869</th>\n",
       "      <td>1044</td>\n",
       "      <td>1044</td>\n",
       "      <td>1044</td>\n",
       "      <td>1044</td>\n",
       "      <td>1044</td>\n",
       "      <td>1044</td>\n",
       "      <td>1044</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9904182060</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9915093501</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9946198589</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9950190890</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9980711012</th>\n",
       "      <td>5</td>\n",
       "      <td>5</td>\n",
       "      <td>5</td>\n",
       "      <td>5</td>\n",
       "      <td>5</td>\n",
       "      <td>5</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>805 rows × 7 columns</p>\n",
       "</div>"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 23
  },
  {
   "cell_type": "code",
   "source": [
    "place_count['x'].describe() #打卡地点总计805个，50%打卡小于2次"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2025-01-22T02:26:38.052384Z",
     "start_time": "2025-01-22T02:26:38.045874Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "count     805.000000\n",
       "mean       22.000000\n",
       "std        88.955632\n",
       "min         1.000000\n",
       "25%         1.000000\n",
       "50%         2.000000\n",
       "75%         5.000000\n",
       "max      1044.000000\n",
       "Name: x, dtype: float64"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 24
  },
  {
   "cell_type": "code",
   "source": [
    "# 只选择去的人大于3的数据，认为1,2,3的是噪音，这个地方去的人很少，不用推荐给其他人\n",
    "# 把index变为0,1,2，3,4,5,6这种效果，从零开始排，原来的index是row_id（因为去掉了一些数据，索引不连续了）\n",
    "tf = place_count[place_count.row_id > 3].reset_index() \n",
    "tf  #剩余的签到地点"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2025-01-22T02:26:38.065882Z",
     "start_time": "2025-01-22T02:26:38.053892Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "       place_id  row_id     x     y  accuracy   day  hour  weekday\n",
       "0    1097200869    1044  1044  1044      1044  1044  1044     1044\n",
       "1    1228935308     120   120   120       120   120   120      120\n",
       "2    1267801529      58    58    58        58    58    58       58\n",
       "3    1278040507      15    15    15        15    15    15       15\n",
       "4    1285051622      21    21    21        21    21    21       21\n",
       "..          ...     ...   ...   ...       ...   ...   ...      ...\n",
       "234  9741307878       5     5     5         5     5     5        5\n",
       "235  9753855529      21    21    21        21    21    21       21\n",
       "236  9806043737       6     6     6         6     6     6        6\n",
       "237  9809476069      23    23    23        23    23    23       23\n",
       "238  9980711012       5     5     5         5     5     5        5\n",
       "\n",
       "[239 rows x 8 columns]"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>place_id</th>\n",
       "      <th>row_id</th>\n",
       "      <th>x</th>\n",
       "      <th>y</th>\n",
       "      <th>accuracy</th>\n",
       "      <th>day</th>\n",
       "      <th>hour</th>\n",
       "      <th>weekday</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1097200869</td>\n",
       "      <td>1044</td>\n",
       "      <td>1044</td>\n",
       "      <td>1044</td>\n",
       "      <td>1044</td>\n",
       "      <td>1044</td>\n",
       "      <td>1044</td>\n",
       "      <td>1044</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1228935308</td>\n",
       "      <td>120</td>\n",
       "      <td>120</td>\n",
       "      <td>120</td>\n",
       "      <td>120</td>\n",
       "      <td>120</td>\n",
       "      <td>120</td>\n",
       "      <td>120</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1267801529</td>\n",
       "      <td>58</td>\n",
       "      <td>58</td>\n",
       "      <td>58</td>\n",
       "      <td>58</td>\n",
       "      <td>58</td>\n",
       "      <td>58</td>\n",
       "      <td>58</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1278040507</td>\n",
       "      <td>15</td>\n",
       "      <td>15</td>\n",
       "      <td>15</td>\n",
       "      <td>15</td>\n",
       "      <td>15</td>\n",
       "      <td>15</td>\n",
       "      <td>15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1285051622</td>\n",
       "      <td>21</td>\n",
       "      <td>21</td>\n",
       "      <td>21</td>\n",
       "      <td>21</td>\n",
       "      <td>21</td>\n",
       "      <td>21</td>\n",
       "      <td>21</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>234</th>\n",
       "      <td>9741307878</td>\n",
       "      <td>5</td>\n",
       "      <td>5</td>\n",
       "      <td>5</td>\n",
       "      <td>5</td>\n",
       "      <td>5</td>\n",
       "      <td>5</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>235</th>\n",
       "      <td>9753855529</td>\n",
       "      <td>21</td>\n",
       "      <td>21</td>\n",
       "      <td>21</td>\n",
       "      <td>21</td>\n",
       "      <td>21</td>\n",
       "      <td>21</td>\n",
       "      <td>21</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>236</th>\n",
       "      <td>9806043737</td>\n",
       "      <td>6</td>\n",
       "      <td>6</td>\n",
       "      <td>6</td>\n",
       "      <td>6</td>\n",
       "      <td>6</td>\n",
       "      <td>6</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>237</th>\n",
       "      <td>9809476069</td>\n",
       "      <td>23</td>\n",
       "      <td>23</td>\n",
       "      <td>23</td>\n",
       "      <td>23</td>\n",
       "      <td>23</td>\n",
       "      <td>23</td>\n",
       "      <td>23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>238</th>\n",
       "      <td>9980711012</td>\n",
       "      <td>5</td>\n",
       "      <td>5</td>\n",
       "      <td>5</td>\n",
       "      <td>5</td>\n",
       "      <td>5</td>\n",
       "      <td>5</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>239 rows × 8 columns</p>\n",
       "</div>"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 25
  },
  {
   "cell_type": "code",
   "source": [
    "# 根据设定的地点目标值，对原本的样本进行过滤，剩下16918条数据\n",
    "# isin可以过滤某一列要在一组值\n",
    "data = data[data['place_id'].isin(tf.place_id)]\n",
    "data.shape"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2025-01-22T02:26:38.078969Z",
     "start_time": "2025-01-22T02:26:38.069256Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(16918, 8)"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 26
  },
  {
   "cell_type": "code",
   "source": [
    "# 取出数据当中的特征值和目标值\n",
    "y = data['place_id']\n",
    "# 删除目标值，保留特征值，\n",
    "x = data.drop(['place_id'], axis=1)\n",
    "# 删除无用的特征值，row_id是索引,这就是噪音\n",
    "x = x.drop(['row_id'], axis=1)\n",
    "print(x.shape)\n",
    "print(x.columns)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2025-01-22T02:26:38.089221Z",
     "start_time": "2025-01-22T02:26:38.080487Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(16918, 6)\n",
      "Index(['x', 'y', 'accuracy', 'day', 'hour', 'weekday'], dtype='object')\n"
     ]
    }
   ],
   "execution_count": 27
  },
  {
   "cell_type": "markdown",
   "source": [
    "# 上面预处理完成"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "source": [
    "# li = load_iris()\n",
    "# x,y=li.data,li.target"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-01-22T02:26:38.094813Z",
     "start_time": "2025-01-22T02:26:38.092218Z"
    }
   },
   "outputs": [],
   "execution_count": 28
  },
  {
   "cell_type": "code",
   "source": [
    "# 进行数据的分割训练集合测试集\n",
    "x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.25, random_state=1)\n",
    "\n",
    "# 特征工程（标准化）,下面3行注释，一开始不进行标准化，看下效果，目标值要不要标准化？\n",
    "std = StandardScaler()\n",
    "# 对测试集和训练集的特征值进行标准化,服务于knn fit\n",
    "x_train = std.fit_transform(x_train)\n",
    "# transform返回的是copy，不在原有的输入对象中去修改\n",
    "# print(id(x_test))\n",
    "print(std.mean_)\n",
    "print(std.var_)\n",
    "\n",
    "x_test = std.transform(x_test)  # transfrom不再进行均值和方差的计算，是在原有的基础上去标准化\n",
    "print('-' * 50)\n",
    "# print(id(x_test))\n",
    "print(std.mean_)\n",
    "print(std.var_)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2025-01-22T02:26:38.108485Z",
     "start_time": "2025-01-22T02:26:38.094813Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[ 1.12295735  2.63237278 81.34938525  5.10064628 11.44293821  3.10135561]\n",
      "[5.98489138e-03 4.86857391e-03 1.19597480e+04 7.32837915e+00\n",
      " 4.83742660e+01 2.81838404e+00]\n",
      "--------------------------------------------------\n",
      "[ 1.12295735  2.63237278 81.34938525  5.10064628 11.44293821  3.10135561]\n",
      "[5.98489138e-03 4.86857391e-03 1.19597480e+04 7.32837915e+00\n",
      " 4.83742660e+01 2.81838404e+00]\n"
     ]
    }
   ],
   "execution_count": 29
  },
  {
   "cell_type": "code",
   "source": [
    "x_train.shape"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-01-22T02:26:38.112880Z",
     "start_time": "2025-01-22T02:26:38.108485Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(12688, 6)"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 30
  },
  {
   "cell_type": "code",
   "source": [
    "# 进行算法流程 \n",
    "# 超参数，可以通过设置n_neighbors=5，来调整结果好坏\n",
    "knn = KNeighborsClassifier(n_neighbors=6)\n",
    "\n",
    "# fit, predict,score，训练，knn的fit是不训练的，只是把训练集的特征值和目标值放入到内存中\n",
    "knn.fit(x_train, y_train)\n",
    "# 得出预测结果\n",
    "y_predict = knn.predict(x_test)\n",
    "\n",
    "print(\"预测的目标签到位置为：\", y_predict[0:10])\n",
    "print(\"实际的目标签到位置为：\", y_test[0:10])\n",
    "# 得出准确率,是评估指标\n",
    "print(\"预测的准确率:\", knn.score(x_test, y_test))\n",
    "# print(y_predict)\n",
    "# y_test"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2025-01-22T02:26:38.443184Z",
     "start_time": "2025-01-22T02:26:38.113380Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "预测的目标签到位置为： [5689129232 1097200869 2355236719 9632980559 6424972551 4022692381\n",
      " 8048985799 6683426742 1435128522 3312463746]\n",
      "实际的目标签到位置为： 16751286    1893548673\n",
      "12423167    1097200869\n",
      "7517023     6097504486\n",
      "4400015     9632980559\n",
      "26212472    6424972551\n",
      "7089828     4022692381\n",
      "10935607    2327054745\n",
      "25025511    3533177779\n",
      "27755137    1435128522\n",
      "19678934    3312463746\n",
      "Name: place_id, dtype: int64\n",
      "预测的准确率: 0.484160756501182\n"
     ]
    }
   ],
   "execution_count": 31
  },
  {
   "cell_type": "code",
   "source": [
    "print(max(time_value))"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2025-01-22T02:26:38.457083Z",
     "start_time": "2025-01-22T02:26:38.444184Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1970-01-10 02:23:38\n"
     ]
    }
   ],
   "execution_count": 32
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": [
    "###### 近似误差与估计误差：\n",
    "- 近似误差：可理解为对现有训练集的训练误差\n",
    "- 估计误差：可理解为对未知数据集的预测误差\n",
    "近似误差关注训练集，近似误差小了会过拟合，对未知的测试样本会出现较大偏差的预测。\n",
    "\n",
    "估计误差关注测试集，估计误差小说明预测能力好，模型本身接近最佳模型"
   ]
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": [
    "1、k 值取多大？有什么影响？\n",
    "- k 值取很小：容易受异常点影响\n",
    "- k 值取很大：容易受最近数据 太多导致比例变化\n",
    "- k 值选择问题，李航博士的一书「统计学习方法」上所说：\n",
    "    - 1)选择较小的 K 值，就相当于用较小的领域中的训练实例进行预测，“学习”近似误差会减小，只有与输入实例较近或相似的训练实例才会对预测结果起作用，与此同时带来的\n",
    "问题是“学习”的估计误差会增大，换句话说，K 值的减小就意味着整体模型变得复杂，容易发生过拟合；（可以思考预测的某个点，有 20 个点到它的距离相等，但是我们 K 取 5）\n",
    "    - 2)选择较大的 K 值，就相当于用较大领域中的训练实例进行预测，其优点是可以减少学习的估计误差，但缺点是学习的近似误差会增大。这时候，与输入实例较远（不相似的）训练实例也会对预测器作用，使预测发生错误，且 K 值的增大就意味着整体的模型变得简单。\n",
    "    - 3)K=N（N 为训练样本个数），则完全不足取，因为此时无论输入实例是什么，都只是简单的预测它属于在训练实例中最多的类，模型过于简单，忽略了训练实例中大量有用信息。\n",
    "- 在实际应用中，K 值一般取一个比较小的数值，例如采用交叉验证法（简单来说，就是把训练数据在分成两组:训练集和验证集）来选择最优的 K 值。\n",
    "\n",
    "2、性能问题？\n",
    "- 时间复杂度问题，样本很多"
   ]
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": [
    "##### k-近邻算法优缺点\n",
    "优点：\n",
    "- 1）算法简单，理论成熟，既可以用来做分类也可以用来做回归。\n",
    "- 2）可用于非线性分类。(Y=kx 是线性）\n",
    "- 3）没有明显的训练过程，而是在程序开始运行时，把数据集加载到内存后，不需要进行训练，直接进行预测，所以训练时间复杂度为 0。\n",
    "- 4）由于 KNN 方法主要靠周围有限的邻近的样本，而不是靠判别类域的方法来确定所属的类别，因此对于类域的交叉或重叠较多的待分类样本集来说，KNN 方法较其他方法更为适合。\n",
    "- 5）该算法比较适用于样本容量比较大的类域的自动分类，而那些样本容量比较小的类域采用这种算法比较容易产生误分类情况。\n",
    "\n",
    "缺点：\n",
    "- 1）需要算每个测试点与训练集的距离，当训练集较大时，计算量相当大，时间复杂度高，特别是特征数量比较大的时候。（预测的时间复杂度高）\n",
    "- 2）需要大量的内存，空间复杂度高。\n",
    "- 3）样本不平衡问题（即有些类别的样本数量很多，而其它样本的数量很少），对稀有类别的预测准确度低。\n",
    "- 4）是 lazy learning 方法，基本上不学习，导致预测时速度比起逻辑回归之类的算法慢。(因为每次预测都需要去计算)"
   ]
  },
  {
   "cell_type": "markdown",
   "source": [
    "# 调超参的方法，网格搜索"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "source": [
    "# 网格搜索时讲解\n",
    "# 构造一些参数（超参）的值进行搜索\n",
    "param = {\"n_neighbors\": [3, 5, 10, 12, 15],'weights':['uniform', 'distance']}\n",
    "\n",
    "# 进行网格搜索，cv=3是3折交叉验证，用其中2折训练，1折验证\n",
    "# 3折即样本分成三份（已经提前留出测试集），分别用一份作为验证集，另外两份作为训练集，最后用这三份数据进行平均，得到一个准确率。\n",
    "gc = GridSearchCV(knn, param_grid=param, cv=3)\n",
    "gc.fit(x_train, y_train)  #你给它的x_train，它又分为训练集，验证集\n",
    "\n",
    "# 预测准确率，为了给大家看看\n",
    "print(\"在测试集上准确率：\", gc.score(x_test, y_test))\n",
    "print(\"在交叉验证当中最好的结果：\", gc.best_score_) #最好的结果\n",
    "print(\"选择最好的模型是：\", gc.best_estimator_) #最好的模型,告诉你用了哪些参数\n",
    "print(\"每个超参数每次交叉验证的结果：\")\n",
    "gc.cv_results_"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2025-01-22T02:26:42.913168Z",
     "start_time": "2025-01-22T02:26:38.457083Z"
    }
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\29470\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\sklearn\\model_selection\\_split.py:805: UserWarning: The least populated class in y has only 1 members, which is less than n_splits=3.\n",
      "  warnings.warn(\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "在测试集上准确率： 0.49763593380614657\n",
      "在交叉验证当中最好的结果： 0.4816362349278435\n",
      "选择最好的模型是： KNeighborsClassifier(n_neighbors=12, weights='distance')\n",
      "每个超参数每次交叉验证的结果：\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "{'mean_fit_time': array([0.01137233, 0.01152126, 0.01548727, 0.01893409, 0.01698295,\n",
       "        0.01133434, 0.01099928, 0.01096574, 0.01246246, 0.01066494]),\n",
       " 'std_fit_time': array([4.46667690e-04, 7.37794793e-04, 3.52074649e-03, 5.73916832e-04,\n",
       "        4.27880484e-03, 4.70754464e-04, 7.37000982e-07, 2.82492202e-05,\n",
       "        1.52346167e-03, 4.73224905e-04]),\n",
       " 'mean_score_time': array([0.13307389, 0.05040892, 0.21504227, 0.11264475, 0.22995925,\n",
       "        0.08152366, 0.14356867, 0.08748714, 0.15659706, 0.10235516]),\n",
       " 'std_score_time': array([0.00500034, 0.0026057 , 0.04659524, 0.00659117, 0.06622229,\n",
       "        0.00388987, 0.0010122 , 0.00306038, 0.00460364, 0.00084761]),\n",
       " 'param_n_neighbors': masked_array(data=[3, 3, 5, 5, 10, 10, 12, 12, 15, 15],\n",
       "              mask=[False, False, False, False, False, False, False, False,\n",
       "                    False, False],\n",
       "        fill_value=999999),\n",
       " 'param_weights': masked_array(data=['uniform', 'distance', 'uniform', 'distance',\n",
       "                    'uniform', 'distance', 'uniform', 'distance',\n",
       "                    'uniform', 'distance'],\n",
       "              mask=[False, False, False, False, False, False, False, False,\n",
       "                    False, False],\n",
       "        fill_value=np.str_('?'),\n",
       "             dtype=object),\n",
       " 'params': [{'n_neighbors': 3, 'weights': 'uniform'},\n",
       "  {'n_neighbors': 3, 'weights': 'distance'},\n",
       "  {'n_neighbors': 5, 'weights': 'uniform'},\n",
       "  {'n_neighbors': 5, 'weights': 'distance'},\n",
       "  {'n_neighbors': 10, 'weights': 'uniform'},\n",
       "  {'n_neighbors': 10, 'weights': 'distance'},\n",
       "  {'n_neighbors': 12, 'weights': 'uniform'},\n",
       "  {'n_neighbors': 12, 'weights': 'distance'},\n",
       "  {'n_neighbors': 15, 'weights': 'uniform'},\n",
       "  {'n_neighbors': 15, 'weights': 'distance'}],\n",
       " 'split0_test_score': array([0.44468085, 0.4534279 , 0.4607565 , 0.47399527, 0.46170213,\n",
       "        0.48014184, 0.45650118, 0.48108747, 0.45508274, 0.47895981]),\n",
       " 'split1_test_score': array([0.43390873, 0.4542445 , 0.45660913, 0.47528967, 0.45542681,\n",
       "        0.48238354, 0.45329865, 0.48049184, 0.44809648, 0.47623552]),\n",
       " 'split2_test_score': array([0.43982029, 0.4561362 , 0.45684559, 0.47221565, 0.4618113 ,\n",
       "        0.48191062, 0.45897375, 0.48332939, 0.46062899, 0.48049184]),\n",
       " 'mean_test_score': array([0.43946996, 0.45460287, 0.45807041, 0.47383353, 0.45964675,\n",
       "        0.48147867, 0.45625786, 0.48163623, 0.45460274, 0.47856239]),\n",
       " 'std_test_score': array([0.00440467, 0.00113433, 0.00190181, 0.00126016, 0.00298428,\n",
       "        0.00096479, 0.00232323, 0.00122169, 0.00512762, 0.00176021]),\n",
       " 'rank_test_score': array([10,  8,  6,  4,  5,  2,  7,  1,  9,  3], dtype=int32)}"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 33
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": [
    "## 混淆矩阵\n",
    "TP  FN   召回率\n",
    "\n",
    "FP  TN\n",
    "\n",
    "精确率    准确率\n",
    "\n",
    "F1-score=2TP/(2TP+FP+FN)=2*精确率*召回率/(精确率+召回率)\n",
    "\n",
    "分类评估模型API\n",
    "\n",
    "ROC曲线与AUC指标\n"
   ]
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "# 2 朴素贝叶斯算法"
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": [
    "# 朴素贝叶斯算法是一种基于贝叶斯定理的分类算法。\n",
    "# 贝叶斯定理：\n",
    "# P(A|B) = P(B|A)P(A)/P(B)"
   ]
  },
  {
   "cell_type": "code",
   "source": [
    "\"\"\"\n",
    "朴素贝叶斯进行文本分类\n",
    ":return: None\n",
    "\"\"\"\n",
    "news = fetch_20newsgroups(subset='all', data_home='data')\n",
    "\n",
    "print(len(news.data))  #样本数，包含的特征\n",
    "print('-'*50)\n",
    "print(news.data[0]) #第一个样本 特征\n",
    "print('-'*50)\n",
    "print(news.target) #标签\n",
    "print(np.unique(news.target)) #标签的类别\n",
    "print(news.target_names) #标签的名字"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2025-01-22T02:27:25.352700Z",
     "start_time": "2025-01-22T02:27:25.149387Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "18846\n",
      "--------------------------------------------------\n",
      "From: Mamatha Devineni Ratnam <mr47+@andrew.cmu.edu>\n",
      "Subject: Pens fans reactions\n",
      "Organization: Post Office, Carnegie Mellon, Pittsburgh, PA\n",
      "Lines: 12\n",
      "NNTP-Posting-Host: po4.andrew.cmu.edu\n",
      "\n",
      "\n",
      "\n",
      "I am sure some bashers of Pens fans are pretty confused about the lack\n",
      "of any kind of posts about the recent Pens massacre of the Devils. Actually,\n",
      "I am  bit puzzled too and a bit relieved. However, I am going to put an end\n",
      "to non-PIttsburghers' relief with a bit of praise for the Pens. Man, they\n",
      "are killing those Devils worse than I thought. Jagr just showed you why\n",
      "he is much better than his regular season stats. He is also a lot\n",
      "fo fun to watch in the playoffs. Bowman should let JAgr have a lot of\n",
      "fun in the next couple of games since the Pens are going to beat the pulp out of Jersey anyway. I was very disappointed not to see the Islanders lose the final\n",
      "regular season game.          PENS RULE!!!\n",
      "\n",
      "\n",
      "--------------------------------------------------\n",
      "[10  3 17 ...  3  1  7]\n",
      "[ 0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19]\n",
      "['alt.atheism', 'comp.graphics', 'comp.os.ms-windows.misc', 'comp.sys.ibm.pc.hardware', 'comp.sys.mac.hardware', 'comp.windows.x', 'misc.forsale', 'rec.autos', 'rec.motorcycles', 'rec.sport.baseball', 'rec.sport.hockey', 'sci.crypt', 'sci.electronics', 'sci.med', 'sci.space', 'soc.religion.christian', 'talk.politics.guns', 'talk.politics.mideast', 'talk.politics.misc', 'talk.religion.misc']\n"
     ]
    }
   ],
   "execution_count": 34
  },
  {
   "cell_type": "code",
   "source": [
    "# 进行数据分割\n",
    "x_train, x_test, y_train, y_test = train_test_split(news.data, news.target, test_size=0.25, random_state=1)\n",
    "\n",
    "# 对数据集进行特征抽取\n",
    "tf = TfidfVectorizer()\n",
    "\n",
    "# 以训练集当中的词的列表进行每篇文章重要性统计['a','b','c','d']\n",
    "x_train = tf.fit_transform(x_train)\n",
    "#针对特征内容，可以自行打印，下面的打印可以得到特征数目，总计有15万特征\n",
    "print(len(tf.get_feature_names_out()))"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2025-01-22T02:31:11.571122Z",
     "start_time": "2025-01-22T02:31:09.014678Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "153196\n"
     ]
    }
   ],
   "execution_count": 35
  },
  {
   "cell_type": "code",
   "source": [
    "print(tf.get_feature_names_out()[100000])"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2025-01-22T02:32:32.939542Z",
     "start_time": "2025-01-22T02:32:32.842213Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "murky\n"
     ]
    }
   ],
   "execution_count": 36
  },
  {
   "cell_type": "code",
   "source": [
    "print(tf.get_feature_names_out()[0:10])"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2025-01-22T02:32:47.397703Z",
     "start_time": "2025-01-22T02:32:47.291133Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['00' '000' '0000' '00000' '0000000004' '0000000005' '0000000667'\n",
      " '0000001200' '000003' '000005102000']\n"
     ]
    }
   ],
   "execution_count": 37
  },
  {
   "cell_type": "code",
   "source": [
    "import time\n",
    "# 进行朴素贝叶斯算法的预测,alpha是拉普拉斯平滑系数，分子和分母加上一个系数，分母加alpha*特征词数目\n",
    "mlt = MultinomialNB(alpha=1.0)\n",
    "\n",
    "# print(x_train.toarray())\n",
    "# 训练\n",
    "start=time.time()\n",
    "mlt.fit(x_train, y_train)\n",
    "end=time.time()\n",
    "end-start #统计训练时间"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2025-01-22T02:32:48.516929Z",
     "start_time": "2025-01-22T02:32:48.408486Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.10379719734191895"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 38
  },
  {
   "cell_type": "code",
   "source": [
    "x_transform_test = tf.transform(x_test)  #特征数目不发生改变\n",
    "print(len(tf.get_feature_names_out())) #查看特征数目"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-01-22T02:34:31.519205Z",
     "start_time": "2025-01-22T02:34:30.755081Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "153196\n"
     ]
    }
   ],
   "execution_count": 39
  },
  {
   "cell_type": "code",
   "source": [
    "start=time.time()\n",
    "y_predict = mlt.predict(x_transform_test)\n",
    "\n",
    "print(\"预测的前面10篇文章类别为：\", y_predict[0:10])\n",
    "\n",
    "# 得出准确率,这个是很难提高准确率，为什么呢？\n",
    "print(\"准确率为：\", mlt.score(x_transform_test, y_test))\n",
    "end=time.time()\n",
    "end-start"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2025-01-22T02:36:18.353354Z",
     "start_time": "2025-01-22T02:36:18.312524Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "预测的前面10篇文章类别为： [16 19 18  1  9 15  1  2 16 13]\n",
      "准确率为： 0.8518675721561969\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "0.0350041389465332"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 42
  },
  {
   "cell_type": "code",
   "source": [
    "#预测的文章数目\n",
    "len(y_predict)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2025-01-22T02:36:21.107916Z",
     "start_time": "2025-01-22T02:36:21.104310Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4712"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 43
  },
  {
   "cell_type": "code",
   "source": [
    "# 目前这个场景我们不需要召回率，support是真实的为那个类别的有多少个样本\n",
    "print(classification_report(y_test, y_predict,\n",
    "      target_names=news.target_names))"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2025-01-22T02:36:30.243615Z",
     "start_time": "2025-01-22T02:36:30.235331Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                          precision    recall  f1-score   support\n",
      "\n",
      "             alt.atheism       0.91      0.77      0.83       199\n",
      "           comp.graphics       0.83      0.79      0.81       242\n",
      " comp.os.ms-windows.misc       0.89      0.83      0.86       263\n",
      "comp.sys.ibm.pc.hardware       0.80      0.83      0.81       262\n",
      "   comp.sys.mac.hardware       0.90      0.88      0.89       234\n",
      "          comp.windows.x       0.92      0.85      0.88       230\n",
      "            misc.forsale       0.96      0.67      0.79       257\n",
      "               rec.autos       0.90      0.87      0.88       265\n",
      "         rec.motorcycles       0.90      0.95      0.92       251\n",
      "      rec.sport.baseball       0.89      0.96      0.93       226\n",
      "        rec.sport.hockey       0.95      0.98      0.96       262\n",
      "               sci.crypt       0.76      0.97      0.85       257\n",
      "         sci.electronics       0.84      0.80      0.82       229\n",
      "                 sci.med       0.97      0.86      0.91       249\n",
      "               sci.space       0.92      0.96      0.94       256\n",
      "  soc.religion.christian       0.55      0.98      0.70       243\n",
      "      talk.politics.guns       0.76      0.96      0.85       234\n",
      "   talk.politics.mideast       0.93      0.99      0.96       224\n",
      "      talk.politics.misc       0.98      0.56      0.72       197\n",
      "      talk.religion.misc       0.97      0.26      0.41       132\n",
      "\n",
      "                accuracy                           0.85      4712\n",
      "               macro avg       0.88      0.84      0.84      4712\n",
      "            weighted avg       0.87      0.85      0.85      4712\n",
      "\n"
     ]
    }
   ],
   "execution_count": 44
  },
  {
   "cell_type": "code",
   "source": [
    "y_test.shape #测试集中有多少 样本"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-01-22T02:37:21.411166Z",
     "start_time": "2025-01-22T02:37:21.407171Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(4712,)"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 45
  },
  {
   "cell_type": "code",
   "source": [
    "# y_test==0的样本变为1，其余变为0\n",
    "y_test1 = np.where(y_test == 0, 1, 0)  # TP+FN=199\n",
    "print(y_test1.sum()) #label为0的样本数"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-01-22T02:41:22.552837Z",
     "start_time": "2025-01-22T02:41:22.548642Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "199\n"
     ]
    }
   ],
   "execution_count": 48
  },
  {
   "cell_type": "code",
   "source": [
    "y_predict1 = np.where(y_predict == 0, 1, 0)  # TP+FP=196\n",
    "print(y_predict1.sum()) "
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-01-22T02:39:30.386105Z",
     "start_time": "2025-01-22T02:39:30.382097Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "168\n"
     ]
    }
   ],
   "execution_count": 47
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "outputs": [
    {
     "data": {
      "text/plain": "153"
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": "(y_test1*y_predict1).sum()  # test1和predict1的交集就是TP（1*1=1）",
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-07-11T08:47:12.871621900Z",
     "start_time": "2024-07-11T08:47:12.859630700Z"
    }
   }
  },
  {
   "cell_type": "code",
   "source": [
    "153/168"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-01-22T02:42:59.931595Z",
     "start_time": "2025-01-22T02:42:59.928279Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.9107142857142857"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 49
  },
  {
   "cell_type": "code",
   "source": [
    "153/199"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-01-22T02:43:00.658635Z",
     "start_time": "2025-01-22T02:43:00.654492Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.7688442211055276"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 50
  },
  {
   "cell_type": "code",
   "source": [
    "max(y_test),min(y_test)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-01-22T02:44:24.351609Z",
     "start_time": "2025-01-22T02:44:24.346508Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(np.int32(19), np.int32(0))"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 52
  },
  {
   "cell_type": "code",
   "source": [
    "# 把0-19总计20个分类，变为0和1\n",
    "# 5是可以改为0到19的\n",
    "y_test1 = np.where(y_test == 5, 1, 0)\n",
    "print(y_test1.sum()) #label为5的样本数\n",
    "y_predict1 = np.where(y_predict == 5, 1, 0)\n",
    "print(y_predict1.sum())\n",
    "# roc_auc_score的y_test只能是二分类,针对多分类如何计算AUC\n",
    "print(\"AUC指标：\", roc_auc_score(y_test1, y_predict1))"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2025-01-22T02:45:13.833631Z",
     "start_time": "2025-01-22T02:45:13.827914Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "230\n",
      "214\n",
      "AUC指标： 0.924078924393225\n"
     ]
    }
   ],
   "execution_count": 54
  },
  {
   "cell_type": "code",
   "source": [
    "y_test1,y_predict1"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-01-22T02:45:15.320975Z",
     "start_time": "2025-01-22T02:45:15.316930Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(array([0, 0, 0, ..., 0, 0, 0], shape=(4712,)),\n",
       " array([0, 0, 0, ..., 0, 0, 0], shape=(4712,)))"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 55
  },
  {
   "cell_type": "code",
   "source": [
    "# 算多分类的精确率，召回率，F1-score\n",
    "FP=np.where((np.array(y_test1)-np.array(y_predict1))==-1,1,0).sum()   # FP是18\n",
    "TP=y_predict1.sum()-FP # TP是196\n",
    "print(TP)\n",
    "FN=np.where((np.array(y_test1)-np.array(y_predict1))==1,1,0).sum() #FN是34\n",
    "print(FN)#FN是1\n",
    "TN=np.where(y_test1==0,1,0).sum()-FP  #4464\n",
    "print(TN)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2025-01-22T03:03:34.644121Z",
     "start_time": "2025-01-22T03:03:34.638958Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "196\n",
      "34\n",
      "4464\n"
     ]
    }
   ],
   "execution_count": 56
  },
  {
   "cell_type": "code",
   "source": [
    "TP/(TP+FP) #精确率"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-01-22T03:03:37.372643Z",
     "start_time": "2025-01-22T03:03:37.368799Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "np.float64(0.9158878504672897)"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 57
  },
  {
   "cell_type": "code",
   "source": [
    "TP/(TP+FN)  #召回率"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-01-22T03:03:39.319811Z",
     "start_time": "2025-01-22T03:03:39.316218Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "np.float64(0.8521739130434782)"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 58
  },
  {
   "cell_type": "code",
   "source": [
    "#F1-score\n",
    "2*TP/(2*TP+FP+FN)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-01-22T03:03:41.732549Z",
     "start_time": "2025-01-22T03:03:41.729076Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "np.float64(0.8828828828828829)"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 59
  },
  {
   "cell_type": "code",
   "source": [
    "del news\n",
    "del x_train\n",
    "del x_test\n",
    "del y_test\n",
    "del y_predict\n",
    "del tf"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2025-01-22T03:09:36.313160Z",
     "start_time": "2025-01-22T03:09:36.291884Z"
    }
   },
   "outputs": [],
   "execution_count": 60
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": [
    "### 拉普拉斯平滑\n",
    "### 朴素贝叶斯分类优缺点\n",
    "\n",
    "优点：\n",
    "- 朴素贝叶斯模型发源于古典数学理论，有稳定的分类效率。\n",
    "- 对缺失数据不太敏感，算法也比较简单，常用于文本分类。\n",
    "- 分类准确度高，速度快\n",
    "\n",
    "缺点：\n",
    "- 需要知道先验概率 P(F1,F2,…|C)，因此在某些时候会由于假设的先验模型的原因导致预测效果不佳。\n",
    "- 假设了文章当中一些词语与另外一些是独立关系—-如果有关系，会造成不太靠谱\n",
    "- 训练集当中去进行统计词这些工作文章收集的不好，比如有作弊文章，充斥某个词会对结果造成干扰\n",
    "- 朴素贝叶斯:文本分类—主要应用领域\n",
    "- 神经网络效果要更好（深度学习）"
   ]
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": ""
  },
  {
   "cell_type": "markdown",
   "source": [
    "# 3 决策树\n",
    "H = -(p1logp1 + p2logp2 + ... + p32logp32) 这是香农公式\n",
    "- H 的专业术语称之为信息熵，单位为比特\n",
    "\n",
    "信息增益g(D,A) = H(D) - H(D|A)\n",
    "- H(D)是初始信息熵大小，H(D|A)是因为条件加入后带来的确定性增加\n",
    "- H(D)是整体熵，H(D|A)条件熵\n",
    "- 注：信息增益表示得知特征 X 的信息而使得类 Y 的信息的不确定性减少的程度"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%% md\n"
    }
   }
  },
  {
   "cell_type": "code",
   "source": [
    "from sklearn.model_selection import train_test_split, GridSearchCV\n",
    "from sklearn.feature_extraction import DictVectorizer\n",
    "from sklearn.tree import DecisionTreeClassifier, export_graphviz\n",
    "from sklearn.ensemble import RandomForestClassifier\n",
    "import pandas as pd\n",
    "import numpy as np"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-01-22T03:10:41.086081Z",
     "start_time": "2025-01-22T03:10:41.082080Z"
    }
   },
   "outputs": [],
   "execution_count": 61
  },
  {
   "cell_type": "code",
   "source": [
    "print(np.log2(1/32))\n",
    "print(1 / 2 * np.log2(1 /2) + 1 / 2 * np.log2(1 /2))\n",
    "print(1 / 3 * np.log2(1 / 3) + 2 / 3 * np.log2(2 / 3))\n",
    "print(0.01 * np.log2(0.01) + 0.99 * np.log2(0.99))"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2025-01-22T03:15:54.929051Z",
     "start_time": "2025-01-22T03:15:54.925766Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "-5.0\n",
      "-1.0\n",
      "-0.9182958340544896\n",
      "-0.08079313589591118\n"
     ]
    }
   ],
   "execution_count": 65
  },
  {
   "cell_type": "code",
   "source": [
    "\"\"\"\n",
    "决策树对泰坦尼克号进行预测生死\n",
    ":return: None\n",
    "\"\"\"\n",
    "# 获取数据\n",
    "titan = pd.read_csv(\"./data/titanic.txt\")\n",
    "titan.info()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2025-01-22T03:21:08.522528Z",
     "start_time": "2025-01-22T03:21:08.509050Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 1313 entries, 0 to 1312\n",
      "Data columns (total 11 columns):\n",
      " #   Column     Non-Null Count  Dtype  \n",
      "---  ------     --------------  -----  \n",
      " 0   row.names  1313 non-null   int64  \n",
      " 1   pclass     1313 non-null   object \n",
      " 2   survived   1313 non-null   int64  \n",
      " 3   name       1313 non-null   object \n",
      " 4   age        633 non-null    float64\n",
      " 5   embarked   821 non-null    object \n",
      " 6   home.dest  754 non-null    object \n",
      " 7   room       77 non-null     object \n",
      " 8   ticket     69 non-null     object \n",
      " 9   boat       347 non-null    object \n",
      " 10  sex        1313 non-null   object \n",
      "dtypes: float64(1), int64(2), object(8)\n",
      "memory usage: 113.0+ KB\n"
     ]
    }
   ],
   "execution_count": 66
  },
  {
   "cell_type": "code",
   "source": [
    "# 处理数据，找出特征值和目标值\n",
    "x = titan[['pclass', 'age', 'sex']]\n",
    "y = titan['survived']\n",
    "print(x.info())  # 用来判断是否有空值\n",
    "x.describe(include='all')"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2025-01-22T03:21:28.518149Z",
     "start_time": "2025-01-22T03:21:28.505712Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 1313 entries, 0 to 1312\n",
      "Data columns (total 3 columns):\n",
      " #   Column  Non-Null Count  Dtype  \n",
      "---  ------  --------------  -----  \n",
      " 0   pclass  1313 non-null   object \n",
      " 1   age     633 non-null    float64\n",
      " 2   sex     1313 non-null   object \n",
      "dtypes: float64(1), object(2)\n",
      "memory usage: 30.9+ KB\n",
      "None\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "       pclass         age   sex\n",
       "count    1313  633.000000  1313\n",
       "unique      3         NaN     2\n",
       "top       3rd         NaN  male\n",
       "freq      711         NaN   850\n",
       "mean      NaN   31.194181   NaN\n",
       "std       NaN   14.747525   NaN\n",
       "min       NaN    0.166700   NaN\n",
       "25%       NaN   21.000000   NaN\n",
       "50%       NaN   30.000000   NaN\n",
       "75%       NaN   41.000000   NaN\n",
       "max       NaN   71.000000   NaN"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>pclass</th>\n",
       "      <th>age</th>\n",
       "      <th>sex</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>1313</td>\n",
       "      <td>633.000000</td>\n",
       "      <td>1313</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>unique</th>\n",
       "      <td>3</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>top</th>\n",
       "      <td>3rd</td>\n",
       "      <td>NaN</td>\n",
       "      <td>male</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>freq</th>\n",
       "      <td>711</td>\n",
       "      <td>NaN</td>\n",
       "      <td>850</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>NaN</td>\n",
       "      <td>31.194181</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>NaN</td>\n",
       "      <td>14.747525</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>NaN</td>\n",
       "      <td>0.166700</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>NaN</td>\n",
       "      <td>21.000000</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>NaN</td>\n",
       "      <td>30.000000</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>NaN</td>\n",
       "      <td>41.000000</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>NaN</td>\n",
       "      <td>71.000000</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ]
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 67
  },
  {
   "cell_type": "code",
   "source": [
    "x.loc[:,'age'].max()"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-01-22T03:23:23.110672Z",
     "start_time": "2025-01-22T03:23:23.106672Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "np.float64(71.0)"
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 68
  },
  {
   "cell_type": "code",
   "source": [
    "# 一定要进行缺失值处理,填为均值\n",
    "mean=x['age'].mean()\n",
    "x.loc[:,'age']=x.loc[:,'age'].fillna(mean)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2025-01-22T03:23:23.707630Z",
     "start_time": "2025-01-22T03:23:23.702955Z"
    }
   },
   "outputs": [],
   "execution_count": 69
  },
  {
   "cell_type": "code",
   "source": [
    "x.info()"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-01-22T03:25:01.983980Z",
     "start_time": "2025-01-22T03:25:01.978427Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 1313 entries, 0 to 1312\n",
      "Data columns (total 3 columns):\n",
      " #   Column  Non-Null Count  Dtype  \n",
      "---  ------  --------------  -----  \n",
      " 0   pclass  1313 non-null   object \n",
      " 1   age     1313 non-null   float64\n",
      " 2   sex     1313 non-null   object \n",
      "dtypes: float64(1), object(2)\n",
      "memory usage: 30.9+ KB\n"
     ]
    }
   ],
   "execution_count": 70
  },
  {
   "cell_type": "code",
   "source": [
    "# 分割数据集到训练集合测试集\n",
    "x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.25, random_state=4)\n",
    "print(x_train.head())"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2025-01-22T03:25:11.200778Z",
     "start_time": "2025-01-22T03:25:11.195442Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "    pclass        age     sex\n",
      "598    2nd  30.000000    male\n",
      "246    1st  62.000000    male\n",
      "905    3rd  31.194181  female\n",
      "300    1st  31.194181  female\n",
      "509    2nd  64.000000    male\n"
     ]
    }
   ],
   "execution_count": 71
  },
  {
   "cell_type": "code",
   "source": [
    "type(x_train)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2025-01-22T03:25:23.120227Z",
     "start_time": "2025-01-22T03:25:23.116366Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "pandas.core.frame.DataFrame"
      ]
     },
     "execution_count": 72,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 72
  },
  {
   "cell_type": "code",
   "source": [
    "sum(y_train)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-01-22T03:25:36.610421Z",
     "start_time": "2025-01-22T03:25:36.607044Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "334"
      ]
     },
     "execution_count": 73,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 73
  },
  {
   "cell_type": "code",
   "source": [
    "# 性别是女性的数量\n",
    "x_train[x_train['sex'] == 'female'].count()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2025-01-22T03:25:50.989374Z",
     "start_time": "2025-01-22T03:25:50.983631Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "pclass    341\n",
       "age       341\n",
       "sex       341\n",
       "dtype: int64"
      ]
     },
     "execution_count": 74,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 74
  },
  {
   "cell_type": "code",
   "source": [
    "y_train"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-01-22T03:26:35.786280Z",
     "start_time": "2025-01-22T03:26:35.781993Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "598     0\n",
       "246     0\n",
       "905     0\n",
       "300     0\n",
       "509     0\n",
       "       ..\n",
       "360     0\n",
       "709     0\n",
       "439     0\n",
       "174     0\n",
       "1146    0\n",
       "Name: survived, Length: 984, dtype: int64"
      ]
     },
     "execution_count": 75,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 75
  },
  {
   "cell_type": "code",
   "source": [
    "# 女性中存活的情况对比\n",
    "z=x_train.copy() # z是为了把特征和目标存储到一起\n",
    "z['survived'] = y_train # 把目标值存储到z中\n",
    "z[z['sex'] == 'female']['survived'].value_counts() # 女性中存活的情况"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-01-22T03:39:02.566231Z",
     "start_time": "2025-01-22T03:39:02.560704Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "survived\n",
       "1    230\n",
       "0    111\n",
       "Name: count, dtype: int64"
      ]
     },
     "execution_count": 86,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 86
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-01-22T03:39:06.067234Z",
     "start_time": "2025-01-22T03:39:06.061703Z"
    }
   },
   "cell_type": "code",
   "source": "z[z['sex'] == 'male']['survived'].value_counts() # 女性中存活的情况",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "survived\n",
       "0    539\n",
       "1    104\n",
       "Name: count, dtype: int64"
      ]
     },
     "execution_count": 87,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 87
  },
  {
   "cell_type": "code",
   "source": "y_train.value_counts() # 没存活的是650，存活的是334",
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-01-22T03:34:08.994304Z",
     "start_time": "2025-01-22T03:34:08.989393Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "survived\n",
       "0    650\n",
       "1    334\n",
       "Name: count, dtype: int64"
      ]
     },
     "execution_count": 82,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 82
  },
  {
   "cell_type": "code",
   "source": [
    "x_train.loc[:,'sex'].value_counts()"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-01-22T03:43:40.875299Z",
     "start_time": "2025-01-22T03:43:40.870044Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "sex\n",
       "male      643\n",
       "female    341\n",
       "Name: count, dtype: int64"
      ]
     },
     "execution_count": 92,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 92
  },
  {
   "cell_type": "code",
   "source": [
    "# 查看未存活的人的数量\n",
    "x_train"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2025-01-22T03:44:16.664422Z",
     "start_time": "2025-01-22T03:44:16.658334Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "     pclass        age     sex\n",
       "598     2nd  30.000000    male\n",
       "246     1st  62.000000    male\n",
       "905     3rd  31.194181  female\n",
       "300     1st  31.194181  female\n",
       "509     2nd  64.000000    male\n",
       "...     ...        ...     ...\n",
       "360     2nd  31.194181    male\n",
       "709     3rd  28.000000    male\n",
       "439     2nd  34.000000    male\n",
       "174     1st  46.000000    male\n",
       "1146    3rd  31.194181    male\n",
       "\n",
       "[984 rows x 3 columns]"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>pclass</th>\n",
       "      <th>age</th>\n",
       "      <th>sex</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>598</th>\n",
       "      <td>2nd</td>\n",
       "      <td>30.000000</td>\n",
       "      <td>male</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>246</th>\n",
       "      <td>1st</td>\n",
       "      <td>62.000000</td>\n",
       "      <td>male</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>905</th>\n",
       "      <td>3rd</td>\n",
       "      <td>31.194181</td>\n",
       "      <td>female</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>300</th>\n",
       "      <td>1st</td>\n",
       "      <td>31.194181</td>\n",
       "      <td>female</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>509</th>\n",
       "      <td>2nd</td>\n",
       "      <td>64.000000</td>\n",
       "      <td>male</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>360</th>\n",
       "      <td>2nd</td>\n",
       "      <td>31.194181</td>\n",
       "      <td>male</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>709</th>\n",
       "      <td>3rd</td>\n",
       "      <td>28.000000</td>\n",
       "      <td>male</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>439</th>\n",
       "      <td>2nd</td>\n",
       "      <td>34.000000</td>\n",
       "      <td>male</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>174</th>\n",
       "      <td>1st</td>\n",
       "      <td>46.000000</td>\n",
       "      <td>male</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1146</th>\n",
       "      <td>3rd</td>\n",
       "      <td>31.194181</td>\n",
       "      <td>male</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>984 rows × 3 columns</p>\n",
       "</div>"
      ]
     },
     "execution_count": 93,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 93
  },
  {
   "cell_type": "code",
   "source": [
    "x_train.to_dict(orient=\"records\") #把df变为字典，样本变为一个一个的字典，字典中列名变为键"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2025-01-22T03:45:34.116748Z",
     "start_time": "2025-01-22T03:45:34.079105Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'pclass': '2nd', 'age': 30.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 62.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 64.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 24.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 21.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 23.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '1st', 'age': 44.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '1st', 'age': 37.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 6.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '1st', 'age': 41.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 30.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 25.0, 'sex': 'female'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 24.0, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 57.0, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 25.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 36.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 51.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 43.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 16.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 19.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 13.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '1st', 'age': 45.0, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 36.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 22.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 30.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 16.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 47.0, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 20.0, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 57.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '1st', 'age': 58.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.0, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 30.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 61.0, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 38.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 27.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 35.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '1st', 'age': 58.0, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 40.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 32.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 21.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 54.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 19.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 38.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 39.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 52.0, 'sex': 'female'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 60.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 11.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 21.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 45.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 18.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 28.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 19.0, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 21.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 21.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 65.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 30.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 28.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 55.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 22.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 36.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 45.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 24.0, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 20.0, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 24.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 15.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 26.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 45.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 35.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 22.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 48.0, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 48.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 30.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 8.0, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 21.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 27.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 45.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 30.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 25.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 18.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 5.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 25.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 39.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 19.0, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 36.0, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 33.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 9.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 26.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 23.0, 'sex': 'female'},\n",
       " {'pclass': '1st', 'age': 17.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '1st', 'age': 36.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 58.0, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 12.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 23.0, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 28.0, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 18.0, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 36.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 32.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 37.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 25.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 49.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 18.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 44.0, 'sex': 'female'},\n",
       " {'pclass': '1st', 'age': 17.0, 'sex': 'female'},\n",
       " {'pclass': '1st', 'age': 23.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 32.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 26.0, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 52.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 28.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 40.0, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 34.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 27.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 20.0, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 22.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 40.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 33.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 18.0, 'sex': 'female'},\n",
       " {'pclass': '1st', 'age': 37.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 24.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 15.0, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 28.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 21.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 30.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 20.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 44.0, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 36.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '1st', 'age': 39.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 13.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 36.0, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 12.0, 'sex': 'female'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 2.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 26.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 27.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 64.0, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 40.0, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 42.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 3.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 5.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '1st', 'age': 22.0, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 36.0, 'sex': 'female'},\n",
       " {'pclass': '1st', 'age': 33.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 45.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 26.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 20.0, 'sex': 'female'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 18.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 22.0, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 54.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 11.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 49.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 39.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 22.0, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 32.0, 'sex': 'female'},\n",
       " {'pclass': '1st', 'age': 45.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 10.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 36.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 18.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '1st', 'age': 18.0, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 22.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 20.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 44.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 30.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 38.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 27.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 36.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 20.0, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 6.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 16.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 0.3333, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 25.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 18.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 31.0, 'sex': 'female'},\n",
       " {'pclass': '1st', 'age': 21.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 17.0, 'sex': 'female'},\n",
       " {'pclass': '1st', 'age': 55.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 30.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 21.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 23.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 40.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 48.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 33.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 49.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 47.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 36.0, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 48.0, 'sex': 'female'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 45.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '1st', 'age': 43.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 52.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 28.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 39.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 9.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 34.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 23.0, 'sex': 'female'},\n",
       " {'pclass': '1st', 'age': 49.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 27.0, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 59.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 28.0, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 41.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 18.0, 'sex': 'female'},\n",
       " {'pclass': '1st', 'age': 27.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 33.0, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 39.0, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 8.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 43.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 44.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 30.0, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 31.0, 'sex': 'female'},\n",
       " {'pclass': '1st', 'age': 36.0, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 25.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 26.0, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 30.0, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '1st', 'age': 31.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 26.0, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 32.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 18.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 61.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 29.0, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 29.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 20.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '1st', 'age': 52.0, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 42.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 2.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 18.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 25.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 17.0, 'sex': 'female'},\n",
       " {'pclass': '1st', 'age': 15.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 19.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 49.0, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 45.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 20.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 3.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 28.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 37.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 57.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 24.0, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 30.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 54.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 3.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 24.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 28.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 24.0, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 25.0, 'sex': 'female'},\n",
       " {'pclass': '1st', 'age': 17.0, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 45.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 48.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 23.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 30.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '1st', 'age': 49.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 0.1667, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 8.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 35.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 34.0, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 23.0, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 33.0, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 7.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 27.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '1st', 'age': 18.0, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 50.0, 'sex': 'female'},\n",
       " {'pclass': '1st', 'age': 39.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 50.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 26.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '1st', 'age': 46.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 35.0, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 25.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 30.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 24.0, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 17.0, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '1st', 'age': 27.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 31.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 33.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 60.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 58.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 20.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 33.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 38.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 30.0, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 21.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 54.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 63.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '1st', 'age': 0.9167, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 11.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 21.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 19.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 24.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 43.0, 'sex': 'female'},\n",
       " {'pclass': '1st', 'age': 2.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 25.0, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 45.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '1st', 'age': 26.0, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '1st', 'age': 56.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 19.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 19.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 4.0, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 45.0, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 22.0, 'sex': 'female'},\n",
       " {'pclass': '1st', 'age': 64.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 32.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 21.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 17.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 55.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 34.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 43.0, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 17.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 51.0, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 35.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 22.0, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 24.0, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 21.0, 'sex': 'female'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 26.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 26.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 27.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 53.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 40.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 41.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 36.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '1st', 'age': 69.0, 'sex': 'female'},\n",
       " {'pclass': '1st', 'age': 24.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 30.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 28.0, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 29.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 24.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 49.0, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 22.0, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 26.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 48.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 47.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 24.0, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 32.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '1st', 'age': 53.0, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 45.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 67.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 2.0, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 32.0, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 2.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 28.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 35.0, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 28.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 6.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 31.0, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 50.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 36.0, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 26.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 56.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 19.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 48.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 31.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 1.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 27.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 16.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 21.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 21.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 1.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 30.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 16.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 25.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 4.0, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 30.0, 'sex': 'female'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 23.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 16.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '1st', 'age': 36.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 23.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 40.0, 'sex': 'female'},\n",
       " {'pclass': '1st', 'age': 58.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 60.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 32.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 39.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 18.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 16.0, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 18.0, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 25.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 27.0, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 42.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 38.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 32.0, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 20.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 13.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 32.0, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 45.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 18.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 29.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 20.0, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 40.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 32.0, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 32.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 23.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 3.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 35.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 37.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 47.0, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 21.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 22.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 22.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 25.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 48.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 24.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 25.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 45.0, 'sex': 'female'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 9.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 59.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 19.0, 'sex': 'female'},\n",
       " {'pclass': '1st', 'age': 19.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 42.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 34.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 42.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 29.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 38.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 33.0, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 19.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 41.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 24.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 34.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 33.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 5.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 18.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 30.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 42.0, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 14.0, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 29.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 30.0, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '1st', 'age': 48.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 18.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 35.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 20.0, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 42.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 17.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 24.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 71.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 29.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 23.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 4.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '1st', 'age': 30.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 22.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 19.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 30.0, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 40.0, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 25.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 6.0, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 50.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '1st', 'age': 71.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 9.0, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 23.0, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 28.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 53.0, 'sex': 'female'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 71.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 46.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 49.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 1.0, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 46.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 37.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 34.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 22.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 19.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 46.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 58.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 22.0, 'sex': 'female'},\n",
       " {'pclass': '1st', 'age': 45.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 35.0, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 41.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 46.0, 'sex': 'female'},\n",
       " {'pclass': '1st', 'age': 36.0, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 24.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 44.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 57.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 9.0, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 23.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 24.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 47.0, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 50.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 50.0, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 34.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 38.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 22.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 18.0, 'sex': 'female'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'female'},\n",
       " {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 31.19418104265403, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 28.0, 'sex': 'male'},\n",
       " {'pclass': '2nd', 'age': 34.0, 'sex': 'male'},\n",
       " {'pclass': '1st', 'age': 46.0, 'sex': 'male'},\n",
       " {'pclass': '3rd', 'age': 31.19418104265403, 'sex': 'male'}]"
      ]
     },
     "execution_count": 94,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 94
  },
  {
   "cell_type": "code",
   "source": [
    "# 进行处理（特征工程）特征-》类别-》one_hot编码\n",
    "dict = DictVectorizer(sparse=False)\n",
    "\n",
    "# 这一步是对字典进行特征抽取,to_dict可以把df变为字典，records代表列名变为键\n",
    "x_train = dict.fit_transform(x_train.to_dict(orient=\"records\"))\n",
    "print(type(x_train))\n",
    "print(dict.get_feature_names_out())\n",
    "print('-' * 50)\n",
    "x_test = dict.transform(x_test.to_dict(orient=\"records\"))\n",
    "print(x_train)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2025-01-22T03:46:48.143478Z",
     "start_time": "2025-01-22T03:46:48.134546Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'numpy.ndarray'>\n",
      "['age' 'pclass=1st' 'pclass=2nd' 'pclass=3rd' 'sex=female' 'sex=male']\n",
      "--------------------------------------------------\n",
      "[[30.          0.          1.          0.          0.          1.        ]\n",
      " [62.          1.          0.          0.          0.          1.        ]\n",
      " [31.19418104  0.          0.          1.          1.          0.        ]\n",
      " ...\n",
      " [34.          0.          1.          0.          0.          1.        ]\n",
      " [46.          1.          0.          0.          0.          1.        ]\n",
      " [31.19418104  0.          0.          1.          0.          1.        ]]\n"
     ]
    }
   ],
   "execution_count": 95
  },
  {
   "cell_type": "code",
   "source": [
    "# 用决策树进行预测，修改max_depth试试,修改criterion为entropy\n",
    "# 树过于复杂，就会产生过拟合\n",
    "dec = DecisionTreeClassifier()\n",
    "\n",
    "# 训练\n",
    "dec.fit(x_train, y_train)\n",
    "\n",
    "# 预测准确率\n",
    "print(\"预测的准确率：\", dec.score(x_test, y_test))\n",
    "\n",
    "# 导出决策树的结构\n",
    "export_graphviz(dec, out_file=\"tree.dot\",\n",
    "                feature_names=['age', 'pclass=1st', 'pclass=2nd', 'pclass=3rd', 'female', 'male'])\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2025-01-22T03:49:26.237414Z",
     "start_time": "2025-01-22T03:49:26.211196Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "预测的准确率： 0.8085106382978723\n"
     ]
    }
   ],
   "execution_count": 96
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
